package com.peaker.advertisingpro.utils

import android.util.Log
import com.ygkj.tasklib.cron4j.Scheduler

/**
 *  @ 作者 CODE_LYF
 *  @ 时间   2021/5/9.
 *  代码人生
 */
object SchedulerUtils {


    var list: MutableSet<String> = mutableSetOf()

    /**
     * 添加定时任务
     */
    fun addScheduler(timeStr: String, method: () -> Unit): String {
         val scheduler = Scheduler()
        val taskId = scheduler.schedule(timeStr) {
            method()
        }
        scheduler.isDaemon = true
        scheduler.start()

//        list.add(taskId)
        return taskId
    }



    /**
     * 设置音量定时任务
     */
    fun addSchedulervolume(timeStr: String, value: String): String {
        Log.d("音量计划","方法添加了")
        val scheduler = Scheduler()
        val taskId = scheduler.schedule(timeStr) {
            SPUtil.putSP(Common.VOLUME,value)
            SmdtManagerUtils.smdtSetAndroidVolume(value.toInt())
            Log.d("音量计划","方法执行了")
        }
        scheduler.isDaemon = true
        scheduler.start()
        list.add(taskId)

        return taskId
    }
    fun clearVolumeTask(){
        list.forEach {

        }
    }

    /**
     * 定时开关机  只需要定时到日期即可
     */
    fun addSchedulerBoot(timeStr: String,offtime:String,ontime:String): String {
        val scheduler = Scheduler()
        val taskId = scheduler.schedule(timeStr) {
            SmdtManagerUtils.smdtSetTimingSwitchMachine(offtime,ontime,"1")
        }
        scheduler.isDaemon = true
        scheduler.start()
        list.add(taskId)
        return taskId
    }



}